package com.ashin;

import com.ashin.job.MyJob;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;

/**
 * Hello world!
 */
public class App {


    public static void main(String[] args) {
        new ScheduleJobBootstrap(createRegistryCenter(), new MyJob(), createJobConfiguration()).schedule();
    }

    private static CoordinatorRegistryCenter createRegistryCenter() {
        ZookeeperConfiguration zkConfig = new ZookeeperConfiguration("192.168.33.52:2181", "my-job");
        zkConfig.setSessionTimeoutMilliseconds(600000);
        zkConfig.setConnectionTimeoutMilliseconds(600000);
        zkConfig.setMaxSleepTimeMilliseconds(30000);
        zkConfig.setBaseSleepTimeMilliseconds(10000);
        CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(zkConfig);
        regCenter.init();
        return regCenter;
    }

    private static JobConfiguration createJobConfiguration() {
        return JobConfiguration.newBuilder("MyJob", 3).cron("0/5 * * * * ?")
                .shardingItemParameters("0=a,1=b,2=c").overwrite(true).build();
    }
}
